package xpn.platform.modules.sys.worktransfer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.web.bind.annotation.*;
import xpn.platform.common.repository.XpnRepositoryController;
import xpn.platform.modules.sys.user.SysUser;
import xpn.platform.modules.sys.user.SysUserDAO;

@RepositoryRestController
@RestController
@RequestMapping("work_transfer")
public class WorkTransferController extends XpnRepositoryController<WorkTransfer, Long> {

    @Autowired
    SysUserDAO userDAO;

    @Autowired
    WorkTransferDAO workTransferDAO;
    /*
  * 通过老信息创建
  */
    @PostMapping(value = "/create_by_old_info")
    public WorkTransfer UpdateState(@RequestParam(defaultValue = "") String from,@RequestParam(defaultValue = "") String to){
        SysUser fromUser=userDAO.findOneByOldId(from);
        SysUser toUser=userDAO.findOneByOldId(to);
        WorkTransfer workTransfer=new WorkTransfer();
        workTransfer.setFrom(fromUser);
        workTransfer.setTo(toUser);
        workTransferDAO.save(workTransfer);
        return workTransfer;
    }
}
